package com;

import java.util.function.Function;

public class TransferAction {

    public int add(int i, int j) {
        return i + j;
    }

    public int mul(int i, int j) {
        return i * j;
    }

    public int cal(int i, Function<Integer, Integer> function) {
        return function.apply(i);
    }

    public static void main(String[] args) {
        TransferAction transferAction = new TransferAction();

        // 之前要想做某个行为要先定义才能调用
        System.out.println(transferAction.add(1, 2));
        System.out.println(transferAction.mul(2, 3));

        // 现在lambda可以传递一个行为，到底是做什么操作由调用者决定，而不需要提取定义
        System.out.println(transferAction.cal(1, (value) -> 1 + value));
        System.out.println(transferAction.cal(2, (value) -> 3 * value));

    }
}
